﻿using System;
using System.Collections.Generic;
using System.Linq;
using DDDSample.Domain.PathFinder;
using NHibernate;

namespace DDDSample.Application.PathFinder
{
    public class CargoInspectionService : ICargoInspectionService
    {
        private readonly ISession _session;
        private readonly Random _random = new Random();      

        public CargoInspectionService(ISession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            _session = session;
        }

        public void InspectCargo(Guid cargoId)
        {

        }

        private int GetRandomNumberOfCandidates()
        {
            return 3 + _random.Next(3);
        }

        private DateTime NextDate(DateTime currentDate)
        {
            return currentDate.AddDays(1).AddMinutes(_random.Next(1000) - 500);
        }

        private IList<String> GetRandomChunkOfLocations(IEnumerable<string> allLocations)
        {
            int total = allLocations.Count();
            int chunk = total > 4 ? 1 + _random.Next(5) : total;
            return allLocations.Select(x => new { Value = x, Index = _random.Next(100) })
               .OrderBy(x => x.Index)
               .Select(x => x.Value)
               .Take(chunk)
               .ToList();
        }

        private TransitEdge GetNextEdge(ref DateTime currentDate, string curr, string next)
        {
            DateTime fromDate = NextDate(currentDate);
            DateTime toDate = NextDate(fromDate);
            currentDate = NextDate(toDate);
            return new TransitEdge(curr, next, fromDate, toDate);
        }
    }
}